package com.zm.spring.jdbc.dao;

import com.zm.spring.jdbc.Bean.OpRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class OpRecordDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    public void insert(OpRecord opRecord){
        jdbcTemplate.update("insert into bank_oprecord values(?,?,?,?,now(),?)",
                opRecord.getId(),
                opRecord.getAid(),
                opRecord.getOpmoney(),
                opRecord.getCharge(),
               opRecord.getRemark());
    }


    public List<Map<String, Object>> selectByAid(int id, int page){
        List<Map<String, Object>> opRecords = (List<Map<String,Object>>) jdbcTemplate.queryForList("select *,t.num from bank_oprecord,(select count(*) as num from bank_oprecord where aid = ?) t where aid = ? order by optime desc limit ?,5",
                id,id,(page -1 )*5);
        return opRecords;
    }


}
